{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "THECOOKIE = \"kpf=PC_WEB; kpn=KUAISHOU_VISION; clientid=3; did=web_ec874916e390b9741609686125a0452e; didv=1613879531823; client_key=65890b29; userId=427400950; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABH8_6ZO8epPD1zM4MX2yDx7KmbQCoXstZcmcJNkTlGj_Tya3xzA_tcreC2GOmRchRAjjbGlGLQ48JvdK9Dus6Cs2OZPgJK78hLnn9Ae8oGM2OOT6xFZZmRnycE_VV6wJO9Xh8CMXAQv32fK8CQuNVbmiWd67Z9_TU9z2cXlMVl_EILJTdoOWiejIMCUdZopywEJdcfxkW_HigiFi5XawZVRoS8JByODRPv5hk-B95zTquvFHcIiC_zxAsoclwICba7h7Nk8LDkfot8fKVOw8ilgOvnzUG0SgFMAE; kuaishou.server.web_ph=14f186b9ecc4a3d35780d2ec154f0b776a75\"\n",
    "\n",
    "\n",
    "URL = \"https://id.kuaishou.com/pass/kuaishou/login/passToken?sid=kuaishou.server.web\"\n",
    "headers = {\n",
    "    \"User-Agent\": \"PostmanRuntime/7.26.8\",\n",
    "    \"Cookie\":r\"clientid=3; did=web_ec874916e390b9741609686125a0452e; didv=1613879531823; client_key=65890b29; userId=427400950; userId=427400950; passToken=ChNwYXNzcG9ydC5wYXNzLXRva2VuErAB09Fn22HHUFs4Muop_XipNpYKJcYFg9Jxuu1cpGUyrlyqwscZGXc02So9rJOGl-aV3Ad5POwpdoopjqlQ7wq35oV0B0mEwKqN-6i7NVeJKJTaNltILNf56B54DZgSGUtMri9iTzj0vtrvpCHEqn7L1rVYT-nGlKOOkFEYauGEOnmDnvjUc7QD2L1sSXzzc4NrUUZhi6O3-kyBsJsymw4a4JkMDJKliJ0QZTu7IYuvqcgaEq_TRjgPx0oylueuj07Lsb3GDSIgnerr8DS_ycF2jLwXujOPPMFSEyNXlE2yqH8OssiW5fQoBTAB\",\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLmF0ErABXPz1K5wn8KbbHgNxTeY3Yv_av9__akdO1aq5PnhfEhK6HE8JKYE0QGYKOqrq6jxbjs2iZKaKiX693U2XvzJMhy42d03IY18-8md9Cr-vaDEIoG53KTtJWvdrc21KLzvawyokGwLgik7upA-XhLvQKJo-_qigGtgKzQsUFKMNaqBJBKHdn1JhvQcOj20U93o8wqPjV76eJU9u8KVIsHvOStFRQW1dIO1Yh-VtpsU9V7gaEvTtWiL8aDAkVchIUtkx8nAjYyIgOkkv3X9h9DWWdOCkDUC1TepbeAIwDD6ezRPFgemD89QoBTAB\n"
     ]
    }
   ],
   "source": [
    "res = requests.post(URL,headers=headers)\n",
    "res.encoding = \"utf-8\"\n",
    "m_json = res.json()  # 字典格式\n",
    "print(m_json[\"kuaishou.server.web.at\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"result\":1,\"kuaishou.server.web_st\":\"ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABeWXYTcPhC6EgoreTvo3qn9pL6EQtnB5SeJQ4HnOJZVwYl_wbRJcd6gwJGTPD0W8kVXFoTJS8Z_h7lLWE-xfxa652YBCAUJcUNxQEX9tRZYJrhkcpUj7yXJdI19kFFtHD9tskDmS2KJ9nR4xuamneQzirWbcTfk5P-S83p5C1HqDQtlYpIoapY3eCRPkoh2AdDyCdFlvW6NagQv1MPCLi7RoS5Uf6LooXNTrpm4StA9DDXaoVIiCX5sF7a7BC8hRQlLpFjByrNLKMKcqvuHvFcfJQXsWutCgFMAE\",\"userId\":427400950,\"kuaishou.server.web_ph\":\"5fe1c81913bb3cd1d7cbcd0264ed28ebda17\",\"sid\":\"kuaishou.server.web\"}\n"
     ]
    }
   ],
   "source": [
    "URL2 = 'https://video.kuaishou.com/rest/infra/sts'\n",
    "headers = {\n",
    "    \"Connection\":\"keep-alive\",\n",
    "    \"User-Agent\": \"PostmanRuntime/7.26.8\",\n",
    "    \"Cookie\":r\"kpf=PC_WEB; kpn=KUAISHOU_VISION; clientid=3; did=web_ec874916e390b9741609686125a0452e; didv=1613879531823; client_key=65890b29; userId=427400950; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABssQl6l3ZcO5tFu_4shEFNlhh-s0CWRRIm36xWGDANPDx6QPnCbqh0mA-TYGd4vv2WrowlcuyPxKMOE1kdVg_AOuxtlRnpS7f8zMVPhZApB2r6ECnb4E_47FJYPeb90TLm5YVDLfYFHAVgpm75p738ANPRImWdfffvHiEqncJdn1gW7yu0CYtyWqdtQbbD2Mus8s7UWF76_yDR1eQsoV9ABoStEyT9S95saEmiR8Dg-bb1DKRIiBuycuMJFuiLwe5GcmxD88aQEj5tcH62oYBN1kzrniFkCgFMAE; kuaishou.server.web_ph=2b4ed626e5e599d8fb6b4d7bfb25ac557f0f\"\n",
    "}\n",
    "params = {\n",
    "    \"authToken\":m_json[\"kuaishou.server.web.at\"],\n",
    "    \"sid\":\"kuaishou.server.web\"\n",
    "}\n",
    "\n",
    "res2 = requests.get(URL2,headers=headers,params=params)\n",
    "content = res2.text\n",
    "print(content)\n",
    "# \"kuaishou.server.web_st\" \"kuaishou.server.web_ph\" 把这两个字段替换掉cookie中，\"userId\"这个字段一直是没变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "# tempCookie = THECOOKIE.split(';')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['{\"result\":1', '\"kuaishou.server.web_st\":\"ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABeWXYTcPhC6EgoreTvo3qn9pL6EQtnB5SeJQ4HnOJZVwYl_wbRJcd6gwJGTPD0W8kVXFoTJS8Z_h7lLWE-xfxa652YBCAUJcUNxQEX9tRZYJrhkcpUj7yXJdI19kFFtHD9tskDmS2KJ9nR4xuamneQzirWbcTfk5P-S83p5C1HqDQtlYpIoapY3eCRPkoh2AdDyCdFlvW6NagQv1MPCLi7RoS5Uf6LooXNTrpm4StA9DDXaoVIiCX5sF7a7BC8hRQlLpFjByrNLKMKcqvuHvFcfJQXsWutCgFMAE\"', '\"userId\":427400950', '\"kuaishou.server.web_ph\":\"5fe1c81913bb3cd1d7cbcd0264ed28ebda17\"', '\"sid\":\"kuaishou.server.web\"}']\n",
      "\"kuaishou.server.web_st\":\"ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABeWXYTcPhC6EgoreTvo3qn9pL6EQtnB5SeJQ4HnOJZVwYl_wbRJcd6gwJGTPD0W8kVXFoTJS8Z_h7lLWE-xfxa652YBCAUJcUNxQEX9tRZYJrhkcpUj7yXJdI19kFFtHD9tskDmS2KJ9nR4xuamneQzirWbcTfk5P-S83p5C1HqDQtlYpIoapY3eCRPkoh2AdDyCdFlvW6NagQv1MPCLi7RoS5Uf6LooXNTrpm4StA9DDXaoVIiCX5sF7a7BC8hRQlLpFjByrNLKMKcqvuHvFcfJQXsWutCgFMAE\"\n",
      "\"kuaishou.server.web_ph\":\"5fe1c81913bb3cd1d7cbcd0264ed28ebda17\"\n"
     ]
    }
   ],
   "source": [
    "# print(tempCookie[7])\n",
    "# print(tempCookie[8])\n",
    "print(content.split(\",\"))\n",
    "tempCont = content.split(\",\")\n",
    "print(tempCont[1])\n",
    "print(tempCont[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['{\"result\":1', '\"kuaishou.server.web_st\":\"ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABeWXYTcPhC6EgoreTvo3qn9pL6EQtnB5SeJQ4HnOJZVwYl_wbRJcd6gwJGTPD0W8kVXFoTJS8Z_h7lLWE-xfxa652YBCAUJcUNxQEX9tRZYJrhkcpUj7yXJdI19kFFtHD9tskDmS2KJ9nR4xuamneQzirWbcTfk5P-S83p5C1HqDQtlYpIoapY3eCRPkoh2AdDyCdFlvW6NagQv1MPCLi7RoS5Uf6LooXNTrpm4StA9DDXaoVIiCX5sF7a7BC8hRQlLpFjByrNLKMKcqvuHvFcfJQXsWutCgFMAE\"', '\"userId\":427400950', '\"kuaishou.server.web_ph\":\"5fe1c81913bb3cd1d7cbcd0264ed28ebda17\"', '\"sid\":\"kuaishou.server.web\"}']\n"
     ]
    }
   ],
   "source": [
    "print(content.split(\",\"))\n",
    "tempCont = content.split(\",\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"kuaishou.server.web_st\":\"ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABeWXYTcPhC6EgoreTvo3qn9pL6EQtnB5SeJQ4HnOJZVwYl_wbRJcd6gwJGTPD0W8kVXFoTJS8Z_h7lLWE-xfxa652YBCAUJcUNxQEX9tRZYJrhkcpUj7yXJdI19kFFtHD9tskDmS2KJ9nR4xuamneQzirWbcTfk5P-S83p5C1HqDQtlYpIoapY3eCRPkoh2AdDyCdFlvW6NagQv1MPCLi7RoS5Uf6LooXNTrpm4StA9DDXaoVIiCX5sF7a7BC8hRQlLpFjByrNLKMKcqvuHvFcfJQXsWutCgFMAE\"\n",
      "\"kuaishou.server.web_ph\":\"5fe1c81913bb3cd1d7cbcd0264ed28ebda17\"\n"
     ]
    }
   ],
   "source": [
    "print(tempCont[1])\n",
    "print(tempCont[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABeWXYTcPhC6EgoreTvo3qn9pL6EQtnB5SeJQ4HnOJZVwYl_wbRJcd6gwJGTPD0W8kVXFoTJS8Z_h7lLWE-xfxa652YBCAUJcUNxQEX9tRZYJrhkcpUj7yXJdI19kFFtHD9tskDmS2KJ9nR4xuamneQzirWbcTfk5P-S83p5C1HqDQtlYpIoapY3eCRPkoh2AdDyCdFlvW6NagQv1MPCLi7RoS5Uf6LooXNTrpm4StA9DDXaoVIiCX5sF7a7BC8hRQlLpFjByrNLKMKcqvuHvFcfJQXsWutCgFMAE\n",
      "5fe1c81913bb3cd1d7cbcd0264ed28ebda17\n"
     ]
    }
   ],
   "source": [
    "# 以：为分割符号\n",
    "st = tempCont[1].split(\":\")[1].replace('\"','')\n",
    "ph = tempCont[3].split(\":\")[1].replace('\"','')\n",
    "print(st)\n",
    "print(ph)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "kpf=PC_WEB; kpn=KUAISHOU_VISION; clientid=3; did=web_ec874916e390b9741609686125a0452e; didv=1613879531823; client_key=65890b29; userId=427400950; kuaishou.ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABeWXYTcPhC6EgoreTvo3qn9pL6EQtnB5SeJQ4HnOJZVwYl_wbRJcd6gwJGTPD0W8kVXFoTJS8Z_h7lLWE-xfxa652YBCAUJcUNxQEX9tRZYJrhkcpUj7yXJdI19kFFtHD9tskDmS2KJ9nR4xuamneQzirWbcTfk5P-S83p5C1HqDQtlYpIoapY3eCRPkoh2AdDyCdFlvW6NagQv1MPCLi7RoS5Uf6LooXNTrpm4StA9DDXaoVIiCX5sF7a7BC8hRQlLpFjByrNLKMKcqvuHvFcfJQXsWutCgFMAE kuaishou.server.web_ph=14f186b9ecc4a3d35780d2ec154f0b776a75\n",
      "kpf=PC_WEB; kpn=KUAISHOU_VISION; clientid=3; did=web_ec874916e390b9741609686125a0452e; didv=1613879531823; client_key=65890b29; userId=427400950; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABH8_6ZO8epPD1zM4MX2yDx7KmbQCoXstZcmcJNkTlGj_Tya3xzA_tcreC2GOmRchRAjjbGlGLQ48JvdK9Dus6Cs2OZPgJK78hLnn9Ae8oGM2OOT6xFZZmRnycE_VV6wJO9Xh8CMXAQv32fK8CQuNVbmiWd67Z9_TU9z2cXlMVl_EILJTdoOWiejIMCUdZopywEJdcfxkW_HigiFi5XawZVRoS8JByODRPv5hk-B95zTquvFHcIiC_zxAsoclwICba7h7Nk8LDkfot8fKVOw8ilgOvnzUG0SgFMAE; kuaishou.server.web_ph=5fe1c81913bb3cd1d7cbcd0264ed28ebda17\n"
     ]
    }
   ],
   "source": [
    "# 然后用正则表达式匹配，然后代替\n",
    "import re\n",
    "cookie_1 = re.sub(r\"server.web_st=(.*);\",st,THECOOKIE)\n",
    "theResult = re.sub(r\"web_ph=(.*)\",\"web_ph=\"+ph,THECOOKIE)\n",
    "print(cookie_1)\n",
    "print(theResult)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['14f186b9ecc4a3d35780d2ec154f0b776a75']\n"
     ]
    }
   ],
   "source": [
    "test = re.findall(r\"server.web_ph=(.*)\",THECOOKIE)\n",
    "print(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
